package com.dxy.hms.socketio.handler;

import com.dxy.hms.socketio.ISession;
import com.dxy.hms.socketio.ISessionService;
import com.dxy.hms.utils.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class HmsOnConnectEventHandler implements com.dxy.hms.socketio.OnConnectEventHandler {

    @Autowired
    private ISessionService sessionService;

    @Override
    public void onConnect(ISession session) {
        String token = session.getConnectParam("token");
        String userId = JwtUtil.getUserId(token);
        sessionService.setUserId(userId, session.getSessionId());
    }
}
